﻿<%@ Page Title="Top 10" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="NewsAggregator._Default" %>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
   
</asp:Content>

<asp:Content runat="server" ID="Content1" ContentPlaceHolderID="Header">
   
<div data-role="header" data-theme="f">
		<h1>Top 10</h1>
    </div><!-- /header -->
    </asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    
    <script type="text/javascript" language="javascript">
        $(document).bind('pageinit', function () {
            $("#liHome").addClass("ui-btn-active");
            $("#liHome").addClass("ui-state-persist");
            $("#liCategory").removeClass("ui-btn-active");
            $("#liSearch").removeClass("ui-btn-active");
        });
        function Related(storyID) {
            window.location = "Related.aspx?story=" + storyID;
        }
        function UpdateHits(newsID) {
            var pageUrl = '<%=ResolveUrl("~/WebService/RecordHitsWS.asmx")%>'
            $.ajax({
                type: "POST",
                url: pageUrl + "/UpdateHits",
                data: "{'newsid':'" + newsID + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccessCall,
                error: OnErrorCall
            });
        }

        function OnSuccessCall(response) {
            
        }

        function OnErrorCall(response) {
            //alert("Error changing the status");
        }

    </script>

	<div data-role="content">
		<ol data-role="listview">
            <asp:Repeater ID="topStroriesRepeater" runat="server">
                    <itemtemplate>
                        <li>
                            <a onclick="UpdateHits('<%# DataBinder.Eval(Container.DataItem, "ID") %>')" href="<%# DataBinder.Eval(Container.DataItem, "Link") %>"><%# DataBinder.Eval(Container.DataItem, "Title") %></a>
                            <span class="ui-li-count"><%# DataBinder.Eval(Container.DataItem, "Hits") %></span>
                            <a href="javascript:Related('<%# DataBinder.Eval(Container.DataItem, "ID") %>')">Related Stories</a>
                        </li>                           
                    </itemtemplate>
            </asp:Repeater>
		</ol>
	</div>



</asp:Content>
